[Java] Embed Rust CLI runtime 4.4: JNA binding interface and implementation - #2230
Conversation
- Add JNA 5.19.1 as optional dependency to java/sdk/pom.xml with jna.version property for deliberate upgrades - Create OutboundCallback.java: JNA Callback interface for native-to-Java outbound data delivery - Create NativeBinding.java: interface abstraction for the 5 copilot_runtime_* C ABI entry points - Create JnaNativeBinding.java: JNA implementation with static singleton (library-never-unloads pattern), duplicate path guard, and active-callback AtomicInteger tracking - Create JnaNativeBindingTest.java: 24 unit tests covering delegation, loading, duplicate guard, and callback behavior using the spike-3-4 test native library - Update module-info.java: requires static com.sun.jna, opens com.github.copilot.ffi to com.sun.jna Co-authored-by: edburns <75821+edburns@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Pull request overview
Adds Java’s JNA bridge to the embedded Rust runtime C ABI.
Changes:
- Defines native binding and callback interfaces.
- Implements guarded JNA library loading and ABI delegation.
- Adds JNA configuration and unit tests.
Show a summary per file
| File | Description |
|---|---|
java/sdk/pom.xml |
Adds optional JNA dependency. |
java/sdk/src/main/java/module-info.java |
Configures JNA module access. |
OutboundCallback.java |
Defines the native callback contract. |
NativeBinding.java |
Defines the internal runtime ABI. |
JnaNativeBinding.java |
Implements JNA loading, delegation, and callback tracking. |
JnaNativeBindingTest.java |
Tests delegation, loading, guards, and callbacks. |
Review details
Suppressed comments (2)
java/sdk/src/main/java/com/github/copilot/ffi/JnaNativeBinding.java:72
- This export returns the runtime's one-byte Rust/C ABI
bool(rust/src/ffi.rs:43), but JNA maps Javabooleanto a 32-bit Cint. That ABI mismatch can decode a nativefalseas true. Use a one-byte native return (or explicit type mapper) and convert it inconnectionClose.
boolean copilot_runtime_connection_close(int connectionId);
java/sdk/src/main/java/com/github/copilot/ffi/JnaNativeBinding.java:69
- This export also returns the runtime's one-byte Rust/C ABI
bool(rust/src/ffi.rs:42), whereas JNA's Javabooleanmapping expects a 32-bit Cint. A nativefalsecan therefore be decoded incorrectly. Use a one-byte native return (or explicit type mapper) and convert it inconnectionWrite.
boolean copilot_runtime_connection_write(int connectionId, byte[] data, int dataLen);
- Files reviewed: 6/6 changed files
- Comments generated: 6
- Review effort level: Balanced
- Fix callback GC: store tracked callbacks per connection in a ConcurrentHashMap, removed on connectionClose (comment #3706039757) - Fix boolean ABI mismatch: Rust bool is 1 byte, JNA maps Java boolean as 32-bit int. Changed CopilotRuntimeLibrary to return byte, convert to boolean in delegation methods (comment #3706039823) - Wrap UnsatisfiedLinkError in IllegalStateException per error contract (comment #3706039855) - Replace silent return with assumeTrue for native lib tests so skips are visible in CI reports (comment #3706039896) - Rewrite activeCallbackCount test to exercise through JnaNativeBinding and assert binding.activeCallbacks (comment #3706039935) - Add ABI name documentation to CallbackTestLib, fix byte return types in test interface (comment #3706039968) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Cross-SDK Consistency Review ✅All 6 changed files in this PR are scoped entirely to Java (
No cross-SDK consistency issues. This is Java-specific native-bridge infrastructure using JNA (Java Native Access), which is a Java ecosystem mechanism with no equivalent in the other SDKs. Each SDK integrates the native runtime through its own platform-appropriate path (Node.js via native modules, Python via ctypes/cffi, Go via cgo, .NET via P/Invoke, Rust natively). No public API surface was added or modified, so no parallel changes are needed in Node.js, Python, Go, .NET, or Rust.
|
357f577
into
edburns/1917-java-embed-rust-cli-runtime-dd-3039924-agentic-run-02
…tation (#2230) * Initial plan * feat(java): add JNA binding interface and implementation (task 4.4) - Add JNA 5.19.1 as optional dependency to java/sdk/pom.xml with jna.version property for deliberate upgrades - Create OutboundCallback.java: JNA Callback interface for native-to-Java outbound data delivery - Create NativeBinding.java: interface abstraction for the 5 copilot_runtime_* C ABI entry points - Create JnaNativeBinding.java: JNA implementation with static singleton (library-never-unloads pattern), duplicate path guard, and active-callback AtomicInteger tracking - Create JnaNativeBindingTest.java: 24 unit tests covering delegation, loading, duplicate guard, and callback behavior using the spike-3-4 test native library - Update module-info.java: requires static com.sun.jna, opens com.github.copilot.ffi to com.sun.jna Co-authored-by: edburns <75821+edburns@users.noreply.github.com> * fix: address Copilot code review findings for JNA binding - Fix callback GC: store tracked callbacks per connection in a ConcurrentHashMap, removed on connectionClose (comment #3706039757) - Fix boolean ABI mismatch: Rust bool is 1 byte, JNA maps Java boolean as 32-bit int. Changed CopilotRuntimeLibrary to return byte, convert to boolean in delegation methods (comment #3706039823) - Wrap UnsatisfiedLinkError in IllegalStateException per error contract (comment #3706039855) - Replace silent return with assumeTrue for native lib tests so skips are visible in CI reports (comment #3706039896) - Rewrite activeCallbackCount test to exercise through JnaNativeBinding and assert binding.activeCallbacks (comment #3706039935) - Add ABI name documentation to CallbackTestLib, fix byte return types in test interface (comment #3706039968) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: edburns <75821+edburns@users.noreply.github.com> Co-authored-by: Ed Burns <edburns@microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…tation (#2230) * Initial plan * feat(java): add JNA binding interface and implementation (task 4.4) - Add JNA 5.19.1 as optional dependency to java/sdk/pom.xml with jna.version property for deliberate upgrades - Create OutboundCallback.java: JNA Callback interface for native-to-Java outbound data delivery - Create NativeBinding.java: interface abstraction for the 5 copilot_runtime_* C ABI entry points - Create JnaNativeBinding.java: JNA implementation with static singleton (library-never-unloads pattern), duplicate path guard, and active-callback AtomicInteger tracking - Create JnaNativeBindingTest.java: 24 unit tests covering delegation, loading, duplicate guard, and callback behavior using the spike-3-4 test native library - Update module-info.java: requires static com.sun.jna, opens com.github.copilot.ffi to com.sun.jna Co-authored-by: edburns <75821+edburns@users.noreply.github.com> * fix: address Copilot code review findings for JNA binding - Fix callback GC: store tracked callbacks per connection in a ConcurrentHashMap, removed on connectionClose (comment #3706039757) - Fix boolean ABI mismatch: Rust bool is 1 byte, JNA maps Java boolean as 32-bit int. Changed CopilotRuntimeLibrary to return byte, convert to boolean in delegation methods (comment #3706039823) - Wrap UnsatisfiedLinkError in IllegalStateException per error contract (comment #3706039855) - Replace silent return with assumeTrue for native lib tests so skips are visible in CI reports (comment #3706039896) - Rewrite activeCallbackCount test to exercise through JnaNativeBinding and assert binding.activeCallbacks (comment #3706039935) - Add ABI name documentation to CallbackTestLib, fix byte return types in test interface (comment #3706039968) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: edburns <75821+edburns@users.noreply.github.com> Co-authored-by: Ed Burns <edburns@microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…tation (#2230) * Initial plan * feat(java): add JNA binding interface and implementation (task 4.4) - Add JNA 5.19.1 as optional dependency to java/sdk/pom.xml with jna.version property for deliberate upgrades - Create OutboundCallback.java: JNA Callback interface for native-to-Java outbound data delivery - Create NativeBinding.java: interface abstraction for the 5 copilot_runtime_* C ABI entry points - Create JnaNativeBinding.java: JNA implementation with static singleton (library-never-unloads pattern), duplicate path guard, and active-callback AtomicInteger tracking - Create JnaNativeBindingTest.java: 24 unit tests covering delegation, loading, duplicate guard, and callback behavior using the spike-3-4 test native library - Update module-info.java: requires static com.sun.jna, opens com.github.copilot.ffi to com.sun.jna Co-authored-by: edburns <75821+edburns@users.noreply.github.com> * fix: address Copilot code review findings for JNA binding - Fix callback GC: store tracked callbacks per connection in a ConcurrentHashMap, removed on connectionClose (comment #3706039757) - Fix boolean ABI mismatch: Rust bool is 1 byte, JNA maps Java boolean as 32-bit int. Changed CopilotRuntimeLibrary to return byte, convert to boolean in delegation methods (comment #3706039823) - Wrap UnsatisfiedLinkError in IllegalStateException per error contract (comment #3706039855) - Replace silent return with assumeTrue for native lib tests so skips are visible in CI reports (comment #3706039896) - Rewrite activeCallbackCount test to exercise through JnaNativeBinding and assert binding.activeCallbacks (comment #3706039935) - Add ABI name documentation to CallbackTestLib, fix byte return types in test interface (comment #3706039968) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: edburns <75821+edburns@users.noreply.github.com> Co-authored-by: Ed Burns <edburns@microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…tation (#2230) * Initial plan * feat(java): add JNA binding interface and implementation (task 4.4) - Add JNA 5.19.1 as optional dependency to java/sdk/pom.xml with jna.version property for deliberate upgrades - Create OutboundCallback.java: JNA Callback interface for native-to-Java outbound data delivery - Create NativeBinding.java: interface abstraction for the 5 copilot_runtime_* C ABI entry points - Create JnaNativeBinding.java: JNA implementation with static singleton (library-never-unloads pattern), duplicate path guard, and active-callback AtomicInteger tracking - Create JnaNativeBindingTest.java: 24 unit tests covering delegation, loading, duplicate guard, and callback behavior using the spike-3-4 test native library - Update module-info.java: requires static com.sun.jna, opens com.github.copilot.ffi to com.sun.jna Co-authored-by: edburns <75821+edburns@users.noreply.github.com> * fix: address Copilot code review findings for JNA binding - Fix callback GC: store tracked callbacks per connection in a ConcurrentHashMap, removed on connectionClose (comment #3706039757) - Fix boolean ABI mismatch: Rust bool is 1 byte, JNA maps Java boolean as 32-bit int. Changed CopilotRuntimeLibrary to return byte, convert to boolean in delegation methods (comment #3706039823) - Wrap UnsatisfiedLinkError in IllegalStateException per error contract (comment #3706039855) - Replace silent return with assumeTrue for native lib tests so skips are visible in CI reports (comment #3706039896) - Rewrite activeCallbackCount test to exercise through JnaNativeBinding and assert binding.activeCallbacks (comment #3706039935) - Add ABI name documentation to CallbackTestLib, fix byte return types in test interface (comment #3706039968) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: edburns <75821+edburns@users.noreply.github.com> Co-authored-by: Ed Burns <edburns@microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…tation (#2230) * Initial plan * feat(java): add JNA binding interface and implementation (task 4.4) - Add JNA 5.19.1 as optional dependency to java/sdk/pom.xml with jna.version property for deliberate upgrades - Create OutboundCallback.java: JNA Callback interface for native-to-Java outbound data delivery - Create NativeBinding.java: interface abstraction for the 5 copilot_runtime_* C ABI entry points - Create JnaNativeBinding.java: JNA implementation with static singleton (library-never-unloads pattern), duplicate path guard, and active-callback AtomicInteger tracking - Create JnaNativeBindingTest.java: 24 unit tests covering delegation, loading, duplicate guard, and callback behavior using the spike-3-4 test native library - Update module-info.java: requires static com.sun.jna, opens com.github.copilot.ffi to com.sun.jna Co-authored-by: edburns <75821+edburns@users.noreply.github.com> * fix: address Copilot code review findings for JNA binding - Fix callback GC: store tracked callbacks per connection in a ConcurrentHashMap, removed on connectionClose (comment #3706039757) - Fix boolean ABI mismatch: Rust bool is 1 byte, JNA maps Java boolean as 32-bit int. Changed CopilotRuntimeLibrary to return byte, convert to boolean in delegation methods (comment #3706039823) - Wrap UnsatisfiedLinkError in IllegalStateException per error contract (comment #3706039855) - Replace silent return with assumeTrue for native lib tests so skips are visible in CI reports (comment #3706039896) - Rewrite activeCallbackCount test to exercise through JnaNativeBinding and assert binding.activeCallbacks (comment #3706039935) - Add ABI name documentation to CallbackTestLib, fix byte return types in test interface (comment #3706039968) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: edburns <75821+edburns@users.noreply.github.com> Co-authored-by: Ed Burns <edburns@microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…tation (#2230) * Initial plan * feat(java): add JNA binding interface and implementation (task 4.4) - Add JNA 5.19.1 as optional dependency to java/sdk/pom.xml with jna.version property for deliberate upgrades - Create OutboundCallback.java: JNA Callback interface for native-to-Java outbound data delivery - Create NativeBinding.java: interface abstraction for the 5 copilot_runtime_* C ABI entry points - Create JnaNativeBinding.java: JNA implementation with static singleton (library-never-unloads pattern), duplicate path guard, and active-callback AtomicInteger tracking - Create JnaNativeBindingTest.java: 24 unit tests covering delegation, loading, duplicate guard, and callback behavior using the spike-3-4 test native library - Update module-info.java: requires static com.sun.jna, opens com.github.copilot.ffi to com.sun.jna Co-authored-by: edburns <75821+edburns@users.noreply.github.com> * fix: address Copilot code review findings for JNA binding - Fix callback GC: store tracked callbacks per connection in a ConcurrentHashMap, removed on connectionClose (comment #3706039757) - Fix boolean ABI mismatch: Rust bool is 1 byte, JNA maps Java boolean as 32-bit int. Changed CopilotRuntimeLibrary to return byte, convert to boolean in delegation methods (comment #3706039823) - Wrap UnsatisfiedLinkError in IllegalStateException per error contract (comment #3706039855) - Replace silent return with assumeTrue for native lib tests so skips are visible in CI reports (comment #3706039896) - Rewrite activeCallbackCount test to exercise through JnaNativeBinding and assert binding.activeCallbacks (comment #3706039935) - Add ABI name documentation to CallbackTestLib, fix byte return types in test interface (comment #3706039968) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: edburns <75821+edburns@users.noreply.github.com> Co-authored-by: Ed Burns <edburns@microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…tation (#2230) * Initial plan * feat(java): add JNA binding interface and implementation (task 4.4) - Add JNA 5.19.1 as optional dependency to java/sdk/pom.xml with jna.version property for deliberate upgrades - Create OutboundCallback.java: JNA Callback interface for native-to-Java outbound data delivery - Create NativeBinding.java: interface abstraction for the 5 copilot_runtime_* C ABI entry points - Create JnaNativeBinding.java: JNA implementation with static singleton (library-never-unloads pattern), duplicate path guard, and active-callback AtomicInteger tracking - Create JnaNativeBindingTest.java: 24 unit tests covering delegation, loading, duplicate guard, and callback behavior using the spike-3-4 test native library - Update module-info.java: requires static com.sun.jna, opens com.github.copilot.ffi to com.sun.jna Co-authored-by: edburns <75821+edburns@users.noreply.github.com> * fix: address Copilot code review findings for JNA binding - Fix callback GC: store tracked callbacks per connection in a ConcurrentHashMap, removed on connectionClose (comment #3706039757) - Fix boolean ABI mismatch: Rust bool is 1 byte, JNA maps Java boolean as 32-bit int. Changed CopilotRuntimeLibrary to return byte, convert to boolean in delegation methods (comment #3706039823) - Wrap UnsatisfiedLinkError in IllegalStateException per error contract (comment #3706039855) - Replace silent return with assumeTrue for native lib tests so skips are visible in CI reports (comment #3706039896) - Rewrite activeCallbackCount test to exercise through JnaNativeBinding and assert binding.activeCallbacks (comment #3706039935) - Add ABI name documentation to CallbackTestLib, fix byte return types in test interface (comment #3706039968) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: edburns <75821+edburns@users.noreply.github.com> Co-authored-by: Ed Burns <edburns@microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…tation (#2230) * Initial plan * feat(java): add JNA binding interface and implementation (task 4.4) - Add JNA 5.19.1 as optional dependency to java/sdk/pom.xml with jna.version property for deliberate upgrades - Create OutboundCallback.java: JNA Callback interface for native-to-Java outbound data delivery - Create NativeBinding.java: interface abstraction for the 5 copilot_runtime_* C ABI entry points - Create JnaNativeBinding.java: JNA implementation with static singleton (library-never-unloads pattern), duplicate path guard, and active-callback AtomicInteger tracking - Create JnaNativeBindingTest.java: 24 unit tests covering delegation, loading, duplicate guard, and callback behavior using the spike-3-4 test native library - Update module-info.java: requires static com.sun.jna, opens com.github.copilot.ffi to com.sun.jna Co-authored-by: edburns <75821+edburns@users.noreply.github.com> * fix: address Copilot code review findings for JNA binding - Fix callback GC: store tracked callbacks per connection in a ConcurrentHashMap, removed on connectionClose (comment #3706039757) - Fix boolean ABI mismatch: Rust bool is 1 byte, JNA maps Java boolean as 32-bit int. Changed CopilotRuntimeLibrary to return byte, convert to boolean in delegation methods (comment #3706039823) - Wrap UnsatisfiedLinkError in IllegalStateException per error contract (comment #3706039855) - Replace silent return with assumeTrue for native lib tests so skips are visible in CI reports (comment #3706039896) - Rewrite activeCallbackCount test to exercise through JnaNativeBinding and assert binding.activeCallbacks (comment #3706039935) - Add ABI name documentation to CallbackTestLib, fix byte return types in test interface (comment #3706039968) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: edburns <75821+edburns@users.noreply.github.com> Co-authored-by: Ed Burns <edburns@microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…tation (#2230) * Initial plan * feat(java): add JNA binding interface and implementation (task 4.4) - Add JNA 5.19.1 as optional dependency to java/sdk/pom.xml with jna.version property for deliberate upgrades - Create OutboundCallback.java: JNA Callback interface for native-to-Java outbound data delivery - Create NativeBinding.java: interface abstraction for the 5 copilot_runtime_* C ABI entry points - Create JnaNativeBinding.java: JNA implementation with static singleton (library-never-unloads pattern), duplicate path guard, and active-callback AtomicInteger tracking - Create JnaNativeBindingTest.java: 24 unit tests covering delegation, loading, duplicate guard, and callback behavior using the spike-3-4 test native library - Update module-info.java: requires static com.sun.jna, opens com.github.copilot.ffi to com.sun.jna Co-authored-by: edburns <75821+edburns@users.noreply.github.com> * fix: address Copilot code review findings for JNA binding - Fix callback GC: store tracked callbacks per connection in a ConcurrentHashMap, removed on connectionClose (comment #3706039757) - Fix boolean ABI mismatch: Rust bool is 1 byte, JNA maps Java boolean as 32-bit int. Changed CopilotRuntimeLibrary to return byte, convert to boolean in delegation methods (comment #3706039823) - Wrap UnsatisfiedLinkError in IllegalStateException per error contract (comment #3706039855) - Replace silent return with assumeTrue for native lib tests so skips are visible in CI reports (comment #3706039896) - Rewrite activeCallbackCount test to exercise through JnaNativeBinding and assert binding.activeCallbacks (comment #3706039935) - Add ABI name documentation to CallbackTestLib, fix byte return types in test interface (comment #3706039968) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: edburns <75821+edburns@users.noreply.github.com> Co-authored-by: Ed Burns <edburns@microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…tation (#2230) * Initial plan * feat(java): add JNA binding interface and implementation (task 4.4) - Add JNA 5.19.1 as optional dependency to java/sdk/pom.xml with jna.version property for deliberate upgrades - Create OutboundCallback.java: JNA Callback interface for native-to-Java outbound data delivery - Create NativeBinding.java: interface abstraction for the 5 copilot_runtime_* C ABI entry points - Create JnaNativeBinding.java: JNA implementation with static singleton (library-never-unloads pattern), duplicate path guard, and active-callback AtomicInteger tracking - Create JnaNativeBindingTest.java: 24 unit tests covering delegation, loading, duplicate guard, and callback behavior using the spike-3-4 test native library - Update module-info.java: requires static com.sun.jna, opens com.github.copilot.ffi to com.sun.jna Co-authored-by: edburns <75821+edburns@users.noreply.github.com> * fix: address Copilot code review findings for JNA binding - Fix callback GC: store tracked callbacks per connection in a ConcurrentHashMap, removed on connectionClose (comment #3706039757) - Fix boolean ABI mismatch: Rust bool is 1 byte, JNA maps Java boolean as 32-bit int. Changed CopilotRuntimeLibrary to return byte, convert to boolean in delegation methods (comment #3706039823) - Wrap UnsatisfiedLinkError in IllegalStateException per error contract (comment #3706039855) - Replace silent return with assumeTrue for native lib tests so skips are visible in CI reports (comment #3706039896) - Rewrite activeCallbackCount test to exercise through JnaNativeBinding and assert binding.activeCallbacks (comment #3706039935) - Add ABI name documentation to CallbackTestLib, fix byte return types in test interface (comment #3706039968) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: edburns <75821+edburns@users.noreply.github.com> Co-authored-by: Ed Burns <edburns@microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…tation (#2230) * Initial plan * feat(java): add JNA binding interface and implementation (task 4.4) - Add JNA 5.19.1 as optional dependency to java/sdk/pom.xml with jna.version property for deliberate upgrades - Create OutboundCallback.java: JNA Callback interface for native-to-Java outbound data delivery - Create NativeBinding.java: interface abstraction for the 5 copilot_runtime_* C ABI entry points - Create JnaNativeBinding.java: JNA implementation with static singleton (library-never-unloads pattern), duplicate path guard, and active-callback AtomicInteger tracking - Create JnaNativeBindingTest.java: 24 unit tests covering delegation, loading, duplicate guard, and callback behavior using the spike-3-4 test native library - Update module-info.java: requires static com.sun.jna, opens com.github.copilot.ffi to com.sun.jna Co-authored-by: edburns <75821+edburns@users.noreply.github.com> * fix: address Copilot code review findings for JNA binding - Fix callback GC: store tracked callbacks per connection in a ConcurrentHashMap, removed on connectionClose (comment #3706039757) - Fix boolean ABI mismatch: Rust bool is 1 byte, JNA maps Java boolean as 32-bit int. Changed CopilotRuntimeLibrary to return byte, convert to boolean in delegation methods (comment #3706039823) - Wrap UnsatisfiedLinkError in IllegalStateException per error contract (comment #3706039855) - Replace silent return with assumeTrue for native lib tests so skips are visible in CI reports (comment #3706039896) - Rewrite activeCallbackCount test to exercise through JnaNativeBinding and assert binding.activeCallbacks (comment #3706039935) - Add ABI name documentation to CallbackTestLib, fix byte return types in test interface (comment #3706039968) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: edburns <75821+edburns@users.noreply.github.com> Co-authored-by: Ed Burns <edburns@microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Implements the
NativeBindinginterface,JnaNativeBindingJNA-backed implementation, andOutboundCallbackJNA callback — the Java bridge to the fivecopilot_runtime_*C ABI entry points exposed byruntime.node.New files
OutboundCallback— JNA@FunctionalInterface Callback; invoked by the native runtime on native threads. Documents thatdatapointer is only valid during invocation and must be copied withPointer.getByteArray(0, len).NativeBinding— Internalinterfaceabstracting the five ABI entry points.interface(not abstract class) for future FFM swappability via MR-JAR; direct instantiation, noServiceLoader.JnaNativeBinding— JNA implementation:CopilotRuntimeLibrary extends Librarymappingcopilot_runtime_*exportsstatic volatileloadedLib/loadedPathfields; once set, never cleared in productionIllegalStateExceptionwith a diagnostic message naming both pathsAtomicInteger activeCallbacksincremented on callback entry, decremented on exit — callers must drain to zero beforeconnection_close/host_shutdownCopilotRuntimeLibrary) andresetForTesting()for unit test isolationJnaNativeBindingTest— 24 unit tests: delegation viaStubRuntimeLibrary, library load/guard, and callback invocation/tracking against the spike-3-4libcallback_testnative library.Modified files
pom.xml— addsnet.java.dev.jna:jna:${jna.version}(5.19.1,<optional>true</optional>); version is a Maven property for deliberate upgrades.module-info.java— addsrequires static com.sun.jnaandopens com.github.copilot.ffi to com.sun.jna(required for JNA reflection access to callback interface methods under JPMS).Usage sketch